package com.zoe.onelink.upms.common.service;

import com.zoe.onelink.upms.common.entity.AuthInfo;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.TokenStore;

import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2018</p>
 * <p>公司: 智业软件</p>
 *
 * @author LinHongKai
 * @date 2022-03-08 19:28
 */
public interface OneLinkTokenStore extends TokenStore {

    String serialize(Object object);

    <T> T deserialize(String objectJsonStr, Class<T> clazz);

    void removeAccessTokenAndRefreshToken(AuthInfo authInfo);

    OAuth2AccessToken readAccessTokenByUsername(String username);

    AuthInfo readAuthInfo(String accessToken);

    List<String> readPermission(String accessToken);

    String readAuthInfoValue(String accessToken);

    /**
     * 刷新授权认证信息
     * 增加这个方法主要为了能单独刷新UsernamePasswordAuthenticationToken中的用户信息
     * @param authInfo
     */
    void flushAuthInfo(AuthInfo authInfo);

    /**
     * 刷新权限信息
     * @param token
     * @param permissions
     */
    void flushPermission(OAuth2AccessToken token, List<String> permissions);

    long doMaintenance();
}
